#!/usr/bin/env perl
use strict;
use warnings;

my %hash;

while(my $line = <STDIN>){
	chomp($line);
	my @cols = split(/\t/,$line);
	
	my $key = $cols[0];
	my $pv = $cols[1];
	my $suv = $cols[2];

	if(exists($hash{$key})){
		my @values = split(/\t/,$hash{$key});
		$pv += $values[0];
		my @suvs = split(/,/,$suv);
		foreach my $uv (@suvs){
			if($uv !~ $values[1]){
				$values[1] = $values[1].",".$uv;
			}
		}
		$hash{$key} = $pv."\t".$values[1];
	} else{
		$hash{$key} = $pv."\t".$suv;
	}
}

while(my ($k,$v) = each %hash){
	my @val = split(/\t/,$v);
	my @suvs = split(/,/,$val[1]);
	printf("%s\t%s\t%s\n",$k,$val[0],$#suvs + 1);
}
